#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <algorithm>


struct Rectangle {
    int x1, y1, x2, y2;
} rects[1010];

/**
 * 计算两个矩阵的相交面积
 * @param r1
 * @param r2
 * @return
 */
inline int IntersectArea(const Rectangle& r1, const Rectangle& r2) {
    int xOverlap = std::max(0, std::min(r1.x2, r2.x2) - std::max(r1.x1, r2.x1));
    int yOverlap = std::max(0, std::min(r1.y2, r2.y2) - std::max(r1.y1, r2.y1));
    return xOverlap * yOverlap;
}

/**
 * 时间复杂度：O(n+m)
 * 空间复杂度：O(n)
 * 
 * 矩阵相交
 * @return
 */
int main() {
    int n;
    scanf("%d", &n);

    for (int i = 0; i < n; i++) {
        scanf("%d %d %d %d", &rects[i].x1, &rects[i].y1, &rects[i].x2, &rects[i].y2);
    }

    int m;
    scanf("%d", &m);

    for (int i = 0; i < m; i++) {
        int x, y;
        scanf("%d %d", &x, &y);

        printf("%d\n", IntersectArea(rects[x - 1], rects[y - 1]));

    }

    return 0;
}



